package com.leyou.order.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.security.PublicKey;

@ConfigurationProperties(prefix = "ly.jwt")
@Data
@Slf4j
public class JwtProperties implements InitializingBean {

    private UserProperies user = new UserProperies();

    private PublicKey publicKey;

    private String pubKeyPath;

    @Data
    public class UserProperies{
        private String cookieName;
    }

    //这个方法在属性setter注入后才执行
    @Override
    public void afterPropertiesSet() throws Exception {
        try {
            // 获取公钥和私钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
        } catch (Exception e) {
            log.error("【购物车】初始化公钥失败！", e);
            throw new RuntimeException(e);
        }
    }
}
